<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 14-12-23
 * Time: 下午8:20
 */


class Db{
    private static $instance;
    private static $dbSocket;
    public $dbConfig=array(
        'dbhost'=>'localhost',
        'dbuser'=>'root',
        'dbpass'=>'123456',
        'dbname'=>'gwang'
    );

    private function __construct(){

    }

    public  static function getInstance(){
        if(!self::$instance instanceof self){
            self::$instance=new self();
        }
        return self::$instance;
    }

    public function connect(){
       if(!self::$dbSocket){
           self::$dbSocket= mysqli_connect($this->dbConfig['dbhost'],$this->dbConfig['dbuser'],$this->dbConfig['dbpass']);
           if(!self::$dbSocket){
               die('mysql connect error');
           }
           mysqli_select_db(self::$dbSocket,$this->dbConfig['dbname']);
       }
        return self::$dbSocket;
    }


}





